package org.com.ashen.web.execute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.com.ashen.common.common.HttpResult;
import org.com.ashen.common.exception.ErrorEnum;
import org.com.ashen.common.exception.SystemException;
import org.com.ashen.service.service.smssendlogmanage.sms.param.BaseParam;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.alibaba.fastjson.JSON;


public class CommonExecutor {
    public static String execute(HttpServletRequest request, HttpServletResponse response, Class<? extends BaseParam> paramClass, CommonExecute commonExecute) {
        //request.getQueryString();
    	BaseParam baseParam = null;
        try {
            baseParam = paramClass.newInstance();
        } catch (InstantiationException e) {
            throw new SystemException(ErrorEnum.RUNTIME_EXCEPTION);
        } catch (IllegalAccessException e) {
            throw new SystemException(ErrorEnum.RUNTIME_EXCEPTION);
        }
       
        new ServletRequestDataBinder(baseParam).bind(request);
        HttpResult result = commonExecute.execute(baseParam);
        return JSON.toJSONString(result);
    }
    
    public static String executesql(HttpServletRequest request, HttpServletResponse response, Class<? extends BaseParam> paramClass, CommonExecute commonExecute) {
        BaseParam baseParam = null;
        try {
            baseParam = paramClass.newInstance();
        } catch (InstantiationException e) {
            throw new SystemException(ErrorEnum.RUNTIME_EXCEPTION);
        } catch (IllegalAccessException e) {
            throw new SystemException(ErrorEnum.RUNTIME_EXCEPTION);
        }
        new ServletRequestDataBinder(baseParam).bind(request);
        HttpResult result = commonExecute.execute(baseParam);
        return JSON.toJSONString(result);
    }
}
